
package Utilities;

import Main.Main;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

/* Start of 'MyDisplay' class */
public class MyDisplay
{
  public Display Disp;

  public Object OldDisplayable[] = new Object[3];
  public int CurPush = 0;
  public Displayable CurDisp = null;
  private static MyDisplay MyDisp = null;

   /* 'MyDisplay' class constrcutor
   * ARGUMENTS:
   *   - program reference
   *       Main Prog;
   * RETURNS: None.
   */
  private MyDisplay( MIDlet Prg )
  {
    Disp = Display.getDisplay(Prg);
  } /* End of 'MyDisplay' class constrcutor */

  /* Initialize display function
   * ARGUMENTS:
   *   - reference to the main midlet class
   *       MIDlet Prg;
   * RETURNS: None.
   */
  public static void Init( MIDlet Prg )
  {
    MyDisp = new MyDisplay(Prg);
  } /* End of 'Init' function */

  /* Is display initialized function
   * ARGUMENTS: None.
   * RETURNS:
   *   - 'true' - if initialized, 'false' - otherwice
   *       boolean;
   */
  public static boolean IsInit( )
  {
    if (MyDisp == null)
      return false;
    return true;
  } /* End of 'IsInit' function */

   /* Switch current display function
   * ARGUMENTS:
   *   - display parameter
   *       Alert alert;
   *   - displayable to be set
   *       Displayable nextDisplayable;
   * RETURNS: None.
   */
  public static void SwitchDisplayable( Alert alert, Displayable nextDisplayable )
  {
    if (MyDisp == null)
      return;
    MyDisp.CurDisp = nextDisplayable;
    if (alert == null)
    {
       MyDisp.Disp.setCurrent(nextDisplayable);
    }
    else
    {
       MyDisp.Disp.setCurrent(alert, nextDisplayable);
    }
  } /* End of 'switchDisplayable' function */

  /* Get current displayable item function
   * ARGUMENTS: None.
   * RETURNS:
   *   - current displayable item
   *       Displayable;
   */
  public static Displayable GetDisplayable( )
  {
     if (MyDisp == null)
       return null;
     return MyDisp.CurDisp;
  } /* End of 'GetDisplayable' function */

  /* Push current displayable object function
   * ARGUMENTS: None.
   * RETURNS: None.
   */
  public static void PushDisplayable( )
  {
    if (MyDisp == null || MyDisp.CurPush == MyDisp.OldDisplayable.length)
      return;
    MyDisp.OldDisplayable[MyDisp.CurPush++] = GetDisplayable();
  } /* End of 'PushDisplayable' function */

  /* Pop pushed displayable object function
   * ARGUMENTS: None.
   * RETURNS: None.
   */
  public static void PopDisplayable( )
  {
    if (MyDisp == null || MyDisp.CurPush == 0)
      return;
    SwitchDisplayable(null, (Displayable)MyDisp.OldDisplayable[--MyDisp.CurPush]);
    MyDisp.OldDisplayable[MyDisp.CurPush] = null;
  } /* End of 'PopDisplayable' function */
} /* End of 'MyDisplay' class */
